﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Menu.aspx.cs" Inherits="Manage_Menu" %>

<html>
<head>
    <link rel="icon" href="pic/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="pic/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <link rel="stylesheet" href="Themes/<%=ManageHelper.GetTheme() %>/style.css" type="text/css" />
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <style type="text/css">
        body
        {
            padding: 0;
            margin: 0;
        }
    </style>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <script language="JavaScript">
        function isNull(obj) {
            if (typeof (obj) == "undefined")
                return true;

            if (obj == undefined)
                return true;
            if (obj == null)
                return true;

            return false;
        }

        function gotoMain(siteid) {
            window.top.location.href = "main.aspx?siteid=" + siteid;
        }

        function openMain(siteid) {
            window.open("main.aspx?siteid=" + siteid);
        }

        //取得Tree的级别，1为第一级
        function getTreeLevel(e) {
            var length = 0;
            if (!isNull(e)) {
                if (e.tagName == 'TR') {
                    length = parseInt(e.getAttribute('treeItemLevel'));
                }
            }
            return length;
        }

        function closeAllFolder() {
            if (isNodeTree) {
                var imgCol = document.getElementsByTagName('IMG');
                if (!isNull(imgCol)) {
                    for (x = 0; x < imgCol.length; x++) {
                        if (!isNull(imgCol.item(x).getAttribute('src'))) {
                            if (imgCol.item(x).getAttribute('src') == 'pic/tree/openedfolder.gif') {
                                imgCol.item(x).setAttribute('src', 'pic/tree/folder.gif');
                            }
                        }
                    }
                }
            }

            var aCol = document.getElementsByTagName('A');
            if (!isNull(aCol)) {
                for (x = 0; x < aCol.length; x++) {
                    if (aCol.item(x).getAttribute('isTreeLink') == 'true') {
                        aCol.item(x).style.fontWeight = 'normal';
                    }
                }
            }
        }

        function openFolderByA(element) {
            closeAllFolder();
            if (isNull(element) || element.tagName != 'A') return;

            element.style.fontWeight = 'bold';

            if (isNodeTree) {
                for (element = element.previousSibling; ; ) {
                    if (element != null && element.tagName == 'A') {
                        element = element.firstChild;
                    }
                    if (element != null && element.tagName == 'IMG') {
                        if (element.getAttribute('src') == 'pic/tree/folder.gif') break;
                        break;
                    } else {
                        element = element.previousSibling;
                    }
                }
                if (!isNull(element)) {
                    element.setAttribute('src', 'pic/tree/openedfolder.gif');
                }
            }
        }

        function getTrElement(element) {
            if (isNull(element)) return;
            for (element = element.parentNode; ; ) {
                if (element != null && element.tagName == 'TR') {
                    break;
                } else {
                    element = element.parentNode;
                }
            }
            return element;
        }

        function getImgClickableElementByTr(element) {
            if (isNull(element) || element.tagName != 'TR') return;
            var img = null;
            if (!isNull(element.childNodes)) {
                var imgCol = element.getElementsByTagName('IMG');
                if (!isNull(imgCol)) {
                    for (x = 0; x < imgCol.length; x++) {
                        if (!isNull(imgCol.item(x).getAttribute('isOpen'))) {
                            img = imgCol.item(x);
                            break;
                        }
                    }
                }
            }
            return img;
        }

        function toggleChildren(element, level) {
            var src = element.src;
            element.src = element.getAttribute("altSrc");
            element.setAttribute("altSrc", src);
            var tr = getTrElement(element);
            for (var e = tr.nextSibling; !isNull(e) && e.tagName == "TR"; e = e.nextSibling) {
                var currentLevel = getTreeLevel(e);
                if (currentLevel <= level) break;
                if (e.style.display == "") {
                    e.style.display = "none";
                    var img = getImgClickableElementByTr(e);
                    if (!isNull(img)) {
                        img.src = element.src;
                        img.setAttribute("altSrc", src);
                    }
                } else {//展开
                    if (currentLevel != level + 1) continue;
                    e.style.display = "";
                }
            }
        }

        //显示、隐藏下级目录
        function displayChildren(element) {
            if (isNull(element)) return;

            var tr = getTrElement(element);

            var img = getImgClickableElementByTr(tr); //需要变换的加减图标

            if (!isNull(img) && img.getAttribute('isOpen') != null) {
                if (img.getAttribute('isOpen') == 'false') {
                    img.setAttribute('isOpen', 'true');
                    img.setAttribute('src', 'pic/tree/minus.gif');
                } else {
                    img.setAttribute('isOpen', 'false');
                    img.setAttribute('src', 'pic/tree/plus.gif');
                }
            }

            var level = getTreeLevel(tr); //点击项菜单的级别

            var collection = new Array();
            var index = 0;

            for (var e = tr.nextSibling; !isNull(e); e = e.nextSibling) {
                if (!isNull(e) && !isNull(e.tagName) && e.tagName == 'TR') {
                    var currentLevel = getTreeLevel(e);
                    if (currentLevel <= level) break;
                    if (e.style.display == '') {
                        e.style.display = 'none';
                    } else {//展开
                        if (currentLevel != level + 1) continue;
                        e.style.display = '';
                        var imgClickable = getImgClickableElementByTr(e);
                        if (!isNull(imgClickable)) {
                            if (!isNull(imgClickable.getAttribute('isOpen')) && imgClickable.getAttribute('isOpen') == 'true') {
                                imgClickable.setAttribute('isOpen', 'false');
                                imgClickable.setAttribute('src', 'pic/tree/plus.gif');
                                collection[index] = imgClickable;
                                index++;
                            }
                        }
                    }
                }
            }

            if (index > 0) {
                for (i = 0; i <= index; i++) {
                    displayChildren(collection[i]);
                }
            }
        }
        var isNodeTree = false;
    </script>

</head>
<body>
    <%
        if (SiteID > 0 && Act == "")
        {
            Response.Write("<div class='lefttab' style='padding-top:7px;'>&nbsp;<a href='" + modelSite.SiteUrl + "' target='_blank'>" + modelSite.SiteName + "</a>&nbsp;<a href='javascript:' title='单独管理模式' target='top' onclick='openMain(" + SiteID + @");' isTreeLink='true'><img align='absmiddle' src='pic/icons/url.gif'/></a></div>");
        }
        else
            Response.Write("<div class='lefttab'>&nbsp;" + ActName + "</div>");
    %>
    <div class="columncontent">
        <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
            <% 
                if (SiteID <= 0 && Act == "")
                    SiteShow();
                else
                    MenuShow(0, true, 1);
    
            %>
        </table>
    </div>
</body>
</html>
